//
//  FMSQLiteDetailCell.m
//  WeEsion
//
//  Created by reylen on 15/12/24.
//  Copyright © 2015年 fdauto. All rights reserved.
//

#import "FMSQLiteDetailCell.h"
#import "UIColor-Extension.h"

@implementation FMSQLiteDetailCell



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier itemCount:(NSInteger) count
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        CGFloat width = [UIScreen mainScreen].bounds.size.width;
        CGFloat _item_width = count * 80 < width ? width/count : 80;
        
        UIColor* lightColor = [UIColor lineColor];
        UIColor* heightColor = [UIColor colorWithHex:@"#8fcdd2"];//COLOR(143, 206, 226);
        
        for (int i = 0; i < count; i ++) {
            UIColor* backColor = i%2 ? heightColor : lightColor;
            UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button setFrame:CGRectMake(_item_width*i, 0, _item_width, self.frame.size.height)];
            button.autoresizingMask = UIViewAutoresizingFlexibleHeight;
            button.backgroundColor = backColor;
            button.titleLabel.numberOfLines = 2;
            [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:14];
            button.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
            [button addTarget:self action:@selector(buttonClickAction:) forControlEvents:UIControlEventTouchUpInside];
            button.tag = 100 + i;
            [self.contentView addSubview:button];
        }
        
    }
    return self;
}

- (IBAction)buttonClickAction:(UIButton *)sender {
//    NSInteger tag = sender.tag - 100;
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:sender.titleLabel.text delegate:nil cancelButtonTitle:@"好" otherButtonTitles:nil, nil];
    [alert show];
    
}

- (void) setContentInfo:(NSDictionary *) info forKeys:(NSArray *) keys {
    
    for (int i = 0; i < keys.count; i ++) {
        UIButton* button = (UIButton *)[self.contentView viewWithTag:i +100];
        if (button) {
            
            NSString* title = [NSString stringWithFormat:@"%@",[info objectForKey:[keys objectAtIndex:i]]];
            [button setTitle:title forState:UIControlStateNormal];
        }
    }
    
}
@end
